﻿using Neural.Managers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neural;
using System.Collections;
using System.Collections.Generic;

namespace NNTest
{
    /// <summary>
    ///This is a test class for ResultSetManagerTest and is intended
    ///to contain all ResultSetManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ResultSetManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for UpdateDataSet
        ///</summary>
        [TestMethod()]
        public void UpdateDataSetTest1()
        {
            ResultSetManager rsm = ResultSetManager.GetManager();
            rsm.VaultDirectory = @"C:\Vault";
            rsm.CleanVault();

            ResultSet data = new ResultSet();
            DataStorageTag dst = new DataStorageTag();
            dst.Description = "Foo data";

            rsm.AddInputData(data, dst, "Foo");

            Dictionary<string, double> inputs, outputs;
            inputs = new Dictionary<string,double>();
            outputs = new Dictionary<string,double>();

            inputs["A"] = 1.0;
            outputs["B"] = 1.0;

            data.AddResult(new Result(inputs, outputs));
            rsm.UpdateDataSet(data, dst, "Foo");

            ResultSet actual = rsm.GetInputData("Foo");
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
        }

        /// <summary>
        ///A test for UpdateDataSet
        ///</summary>
        [TestMethod()]
        public void UpdateDataSetTest()
        {
            ResultSetManager target = ResultSetManager.GetManager();
            target.VaultDirectory = @"C:\Vault";
            target.CleanVault();

            ResultSet data = new ResultSet(); // TODO: Initialize to an appropriate value
            DataStorageTag dst = new DataStorageTag();
            target.AddInputData(data, new DataStorageTag(), "Foo");
            
            Dictionary<string, double> inputs = new Dictionary<string, double>();
            Dictionary<string, double> outputs = new Dictionary<string, double>();
            inputs["Foo"] = 1.0;
            outputs["Bar"] = 1.0;

            data.AddResult(new Result(inputs, outputs));
            target.UpdateDataSet(data, "Foo");

            ResultSet actual = target.GetInputData("Foo");

            Assert.AreEqual(1, target.ListResultSets().Count);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(1.0, actual[0].Inputs["Foo"], 0.001);
            Assert.AreEqual(1.0, actual[0].Outputs["Bar"], 0.001);
        }

        /// <summary>
        ///A test for ListResultSets
        ///</summary>
        [TestMethod()]
        public void ListResultSetsTest()
        {
            ResultSetManager target = ResultSetManager.GetManager();
            target.VaultDirectory = @"C:\Vault";
            target.CleanVault();

            target.AddInputData(new ResultSet(), new DataStorageTag(), "Foobar");
            target.AddInputData(new ResultSet(), new DataStorageTag(), "Barfoo");

            ArrayList list = target.ListResultSets();
            Assert.AreEqual(2, list.Count);
        }

        /// <summary>
        ///A test for getStorageTag
        ///</summary>
        [TestMethod()]
        public void GetStorageTagTest()
        {
            ResultSetManager target = ResultSetManager.GetManager();
            target.VaultDirectory = @"C:\Vault";
            target.CleanVault();
            
            DataStorageTag dst = new DataStorageTag();
            ResultSet rs = new ResultSet();

            target.AddInputData(rs, dst, "Foobar2");

            dst = target.GetStorageTag("Foobar2");
            Assert.IsNotNull(dst);
        }

        /// <summary>
        ///A test for GetManager
        ///</summary>
        [TestMethod()]
        public void GetManagerTest()
        {
            ResultSetManager rsm1 = ResultSetManager.GetManager();
            Assert.IsNotNull(rsm1);

            ResultSetManager rsm2 = ResultSetManager.GetManager();
            Assert.ReferenceEquals(rsm1, rsm2);
        }

        /// <summary>
        ///A test for GetInputData
        ///</summary>
        [TestMethod()]
        public void GetInputDataTest()
        {
            ResultSetManager target = ResultSetManager.GetManager();
            target.VaultDirectory = @"C:\Vault";
            target.CleanVault();

            DataStorageTag dst = new DataStorageTag();
            ResultSet rs = new ResultSet();

            target.AddInputData(rs, dst, "Foobar");

            ResultSet actual = target.GetInputData("Foobar");

            Assert.IsNotNull(actual);
        }

        /// <summary>
        ///A test for CleanVault
        ///</summary>
        [TestMethod()]
        public void CleanVaultTest()
        {
            ResultSetManager target = ResultSetManager.GetManager(); // TODO: Initialize to an appropriate value
            target.CleanVault();

            Assert.AreEqual(0, target.ListResultSets().Count);
        }

        /// <summary>
        ///A test for addInputData
        ///</summary>
        [TestMethod()]
        public void AddInputDataTest()
        {
            ResultSetManager target = ResultSetManager.GetManager();
            ResultSet data = new ResultSet();
            Dictionary<string, double> inputs, outputs;
            inputs = new Dictionary<string, double>();
            outputs = new Dictionary<string, double>();

            inputs["Foo"] = 1.0;
            outputs["Bar"] = 1.0;

            data.AddResult(new Result(inputs, outputs));

            DataStorageTag tag = new DataStorageTag();
            tag.Description = "Barmax";

            target.AddInputData(data, tag, "Foobar");
            ResultSet actual = target.GetInputData("Foobar");
            Assert.AreEqual(actual[0].Inputs["Foo"], 1.0, 0.001);
        }

        /// <summary>
        ///A test for ResultSetManager Constructor
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Neural.NET.dll")]
        public void ResultSetManagerConstructorTest()
        {
            ResultSetManager_Accessor target = new ResultSetManager_Accessor();
            Assert.Inconclusive("TODO: Implement code to verify target");
        }
    }
}
